package school.baby.nem165.ui;

import school.baby.nem165.R;
import school.baby.nem165.util.ContainerHolder;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;

import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.facebook.AppEventsLogger;
import com.google.tagmanager.Container;
import com.google.tagmanager.ContainerOpener;
import com.google.tagmanager.ContainerOpener.OpenType;
import com.google.tagmanager.Logger.LogLevel;
import com.google.tagmanager.TagManager;

/*import com.ubertesters.sdk.LockingMode;
 import com.ubertesters.sdk.Ubertesters;*/

public abstract class BaseActivity extends SherlockFragmentActivity implements
		OnClickListener {
	private static final long TIMEOUT_FOR_CONTAINER_OPEN_MILLISECONDS = 2000;
	private AppEventsLogger logger;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// toolBarAdapter = MainToolBar.getInstance(this,
		// MainToolBar.TOOL_SET_SHOW_ALL);

		TagManager tagManager = TagManager.getInstance(getBaseContext());

		// Modify the log level of the logger to print out not only
		// warning and error messages, but also verbose, debug, info messages.
		tagManager.getLogger().setLogLevel(LogLevel.VERBOSE);

		// The containerAvailable method will be called as soon as one of the
		// following happens:
		// 1. a saved container is loaded
		// 2. if there is no saved container, a network container is loaded
		// 3. the 2-second timeout occurs

		logger = AppEventsLogger.newLogger(this);

		ContainerOpener.openContainer(tagManager,
				getString(R.string.google_tag_manager_id),
				OpenType.PREFER_NON_DEFAULT,
				TIMEOUT_FOR_CONTAINER_OPEN_MILLISECONDS,
				new ContainerOpener.Notifier() {

					@Override
					public void containerAvailable(Container container) {
						// Save container for use by any other activities in the
						// app.
						ContainerHolder.setContainer(container);
					}
				});
		// Ubertesters.initialize(getApplication(),
		// LockingMode.LockingModeLockAppIfBuildNotExist);
	}

	public AppEventsLogger getLogerFacebook() {
		return logger;
	}

	@Override
	protected void onResume() {
		super.onResume();
		AppEventsLogger.activateApp(this, getString(R.string.facebook_app_id));
	}

	/**
	 * Show progress view
	 * 
	 * @param message
	 *            - the progress message to show
	 */
	public void showProgress(String message) {

		InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
		inputManager.hideSoftInputFromWindow((null == getCurrentFocus()) ? null
				: getCurrentFocus().getWindowToken(),
				InputMethodManager.HIDE_NOT_ALWAYS);

		if (findViewById(R.id.mainFragment) != null) {
			findViewById(R.id.mainFragment).setVisibility(View.GONE);
		}

	}
	@Override
    public void onClick(View v) {
    	
        Intent intent = null;
        switch (v.getId()) {
        default:
            intent = null;
            break;
        }

    }
	/*
	 * @Override protected void onStart() { super.onStart();
	 * Utility.pushOpenScreenEvent(this.getApplicationContext(),
	 * getStringResourceByName(this.getClass().getSimpleName())); }
	 * 
	 * @Override protected void onStop() { super.onStop();
	 * Utility.pushCloseScreenEvent(this.getApplicationContext(),
	 * getStringResourceByName(this.getClass().getSimpleName())); }
	 */
}
